package za.co.smartmi.service;

import java.util.Date;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * A simple Spring emailer service.
 * This service can be expanded and added to, if more features are needed.
 * @author dudley
 */
@Service("simpleEmailService")
public class SimpleEmailServiceImpl implements SimpleEmailService {

    private static final Logger log = Logger.getLogger(SimpleEmailServiceImpl.class);
    @Autowired
    private JavaMailSender mailSender;
    @Autowired
    private SimpleMailMessage mailMessage;

    /**
     * Email a simple message
     * @param message 
     */
    @Override
    public void emailMessage(String message) {
        SimpleMailMessage mailErrorMessage = new SimpleMailMessage(mailMessage);
        mailErrorMessage.setSentDate(new Date());
        mailErrorMessage.setText(message);
        mailSender.send(mailErrorMessage);
    }
}
